<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\facade\Basic;
use app\admin\service\SellerProductPrice as ServiceSellerProductPrice;
use think\Request;

/**
 *   商品价格/趋势
 */
class SellerProductPrice extends BaseController
{
    /**
     *   获取枚举
     */
    public function resource(Request $request)
    {
        $param['field'] = $request->param('field');
        $serviceSellerProductPrice = new ServiceSellerProductPrice();
        $result = $serviceSellerProductPrice->getEnum($param);
        return Basic::json($result);
    }

    /**
     *  供应商/零售商
     */
    public function getList(Request $request)
    {
        $param['pageIndex'] = $request->param('pageIndex',1);
        $param['pageSize'] = $request->param('pageSize',50);

        /* 必填参数 */
        $param['start_date'] = $request->param('start_date','');
        $param['end_date'] = $request->param('end_date','');
        $param['model_id'] = $request->param('model_id',null);


        /* 可选 */
        $param['seller_id'] = $request->param('seller_id',null);
        $param['seller_category'] = $request->param('seller_category',null);
        $param['inventory_status'] = $request->param('inventory_status',null);
        $param['presale_time'] = $request->param('presale_time',null);
        $param['status'] = $request->param('status',null);

        /* 验证 */
        $this->validateData($param,'SellerProductPrice.getList');

        $serviceSellerProductPrice = new ServiceSellerProductPrice();
        $result = $serviceSellerProductPrice->getList($param);
        return Basic::json($result);

    }


    /**
     *  价格趋势数据
    */
    public function getTrend(Request $request)
    {
        /* 必填参数 */
        $param['start_date'] = $request->param('start_date',null);
        $param['end_date'] = $request->param('end_date',null);
        $param['model_id'] = $request->param('model_id',null);

        /* 预售时间 */
        $param['inventory_status'] = $request->param('inventory_status',null);
        $param['presale_start_date'] = $request->param('presale_start_date',null);
        $param['presale_end_date'] = $request->param('presale_end_date',null);


        $param['seller_id'] = $request->param('seller_id',[]);


        /* 验证 */
        $this->validateData($param,'SellerProductPrice.getTrend');

        $serviceRetrieve = new ServiceSellerProductPrice();
        $result = $serviceRetrieve->getTrend($param);
        return Basic::json($result);
    }

    /**
     *  价格趋势数据
     */
    public function getTrendList(Request $request)
    {
        /* 必填参数 */

        $param['model_id'] = $request->param('model_id',null);
        $param['start_date'] = $request->param('start_date',null);
        $param['end_date'] = $request->param('end_date',null);
        /* 预售时间 */
        $param['inventory_status'] = $request->param('inventory_status',null);
        $param['presale_start_date'] = $request->param('presale_start_date',null);
        $param['presale_end_date'] = $request->param('presale_end_date',null);
        $param['seller_id'] = $request->param('seller_id',[]);

        /* 验证 */
        $this->validateData($param,'SellerProductPrice.getTrend');

        $serviceRetrieve = new ServiceSellerProductPrice();
        $result = $serviceRetrieve->getTrendList($param);
        return Basic::json($result);
    }
    /**
     *   价格趋势数据统计
     */
    public function getCount(Request $request)
    {

        /* 必填参数 */
        $param['start_date'] = $request->param('start_date',null);
        $param['end_date'] = $request->param('end_date',null);
        $param['model_id'] = $request->param('model_id',null);
        $param['seller_id'] = $request->param('seller_id',[]);

        /* 验证 */
        //$this->validateData($param,'SellerProductPrice.getTrend');

        $serviceRetrieve = new ServiceSellerProductPrice();
        $result = $serviceRetrieve->getCount($param);
        return Basic::json($result);

    }


}
